package testgaher;

import java.util.ArrayList;

/**
 * Created with IntelliJ IDEA.
 * Description:关于集合的练习
 * User: 86184
 * Date: 2023-09-26
 * Time: 11:22
 */
public class TestArraysList3 {
    public static void main(String[] args) {
        ArrayList<Integer> nums = new ArrayList<>();//泛型<>是对应的引用
        nums.add(98);
        nums.add(198);
        nums.add(87);
        nums.add(880);
        nums.add(1355);

        for (Integer x : nums) {
            System.out.print(x+" ");
        }
        System.out.println();

        for (Integer x : nums) {
            if(x % 2 == 0)
                System.out.print(x+" ");
        }
        System.out.println();

        for (Integer x : nums) {
            if(x >= 100 && x <= 999)
                System.out.print(x+" ");
        }
        System.out.println();

        int sum = 0;
        for (Integer x : nums) {
            sum += x;
        }
        System.out.println("sum = "+sum);
        System.out.println("avg = "+(double)sum / nums.size());
    }


    public static void main1(String[] args) {
        ArrayList<Integer> nums = new ArrayList<>();//泛型<>是对应的引用
        nums.add(98);
        nums.add(198);
        nums.add(87);
        nums.add(880);
        nums.add(1355);

        System.out.println(nums);
        /**for(int i = 0; i < nums.size(); i++){
            System.out.print(nums.get(i)+" ");
        }
        System.out.println();
        System.out.println("------------------");*/

        for(int i = 0; i < nums.size(); i++){
            if(nums.get(i) % 2 == 0){
                System.out.print(nums.get(i)+" ");
            }
        }
        System.out.println();
        System.out.println("--------------------");

        for(int i = 0; i < nums.size(); i++){
            if(nums.get(i) >= 100 && nums.get(i) <= 999){
                System.out.print(nums.get(i)+" ");
            }
        }
        System.out.println();
        System.out.println("________________________");

        int sum = 0;
        for(int i = 0; i < nums.size(); i++){
            sum += nums.get(i);
        }
        System.out.println("sum = "+sum);
        System.out.println("avg = "+(double)sum / nums.size());
    }
}
